<template>
  <div class="about">
    <button @click="headleSubtract">
      <!-- <h2>About：渐渐--</h2> -->
    </button>
  </div>
</template>
<script>
export default {
  data() {
    return {};
  },
  mounted() {
    // 对象遍历
    const obj = { a: 1, b: 2, c: 3 };
    for (let n in obj) {
      console.log(n, obj[n]);
    }

    // // Object.values把对象的值转换为数组
    // let result = Object.values(obj)

    //es8特性 遍历对象
    for (let [key, value] of Object.entries(obj)) {
      console.log(`key: ${key} value:${value}`);
    }

    // flat() 方法会按照一个可指定的深度递归遍历数组，并将所有元素与遍历到的子数组中的元素合并为一个新数组返回
    // flat()方法最基本的作用就是数组降维
    var arr2 = [1, 2, [3, 4, [5, 6]], [3, [4, [5, 6]]]];
    console.log([...new Set(arr2.flat(Infinity))]); //Infinity 无穷

    //平层数组
    // let result = arr1.flatMap(x => [x * 2]);;
    // console.log(result);

    // 对象扩展  .../assign 
    let dest = { name: "111", sex: "男",a:"哈哈哈" };
    let person = { name: "111", sex: "男", age: 18,a:"钉钉" };
    console.log(Object.assign(dest, person));
    console.log({ ...dest, ...person });


    // 普通数组去重
    let list = [...new Set(["1", "qq", "bb", "hh", "qq"])];
    console.log(list);

    let arr = [
      {
        value: "1",
        lable: "1",
      },
      {
        value: "1",
        lable: "1",
      },
      {
        value: "2",
        lable: "2",
      },
      {
        value: "2",
        lable: "3",
      },
    ];
    //对象数组去重
    const res = new Map();
    let result = arr.filter((arr) => !res.has(arr.value) && res.set(arr.value, 1));
    console.log(result);

    // 对象转换成数组
    const values = Object.values(obj);
    const keys = Object.keys(obj);
    console.log(keys);
    console.log(values);
  },
  methods: {
    headleSubtract() {
      this.$store.dispatch("jian", 2);
    },
  },
};
</script>
